package com.huanong.it.xwadmin.authority.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huanong.it.xwadmin.authority.domain.UserRole;
import com.huanong.it.xwadmin.authority.mapper.UserRoleMapper;
import com.huanong.it.xwadmin.authority.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author Limhuang
* @description 针对表【sys_user_role】的数据库操作Service实现
* @createDate 2024-06-23 22:12:37
*/
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
    implements UserRoleService {

    @Override
    public List<Long> getRolesByUser(Long userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("SELECT DISTINCT role_id");
        queryWrapper.lambda().eq(UserRole::getUserId, userId);
        List<UserRole> userRoles = this.list(queryWrapper);
        List<Long> roleIds = new ArrayList<>();
        userRoles.stream().forEach(userRole -> {
            roleIds.add(userRole.getRoleId());
        });
        return roleIds;
    }
}




